<?php
/*
 * Twitter Module
 * @version 1.0
*/
global $fts_tweeted;
require_once( dirname(__FILE__) . '/class.tweeted.1.0.php');
function fts_tweet($post_ID, $url){
	global $fts_tweeted;
	$got_tweet = get_post_meta($post_ID, 'tweet', true);
	if (!$got_tweet){
		$user = $fts_tweeted['tweet_user'];
		$pass = $fts_tweeted['tweet_pass'];
	
		$tweet = new tweeted();
		$tweet->user = $user;
		$tweet->pass = $pass;
		$tweet->msg = get_the_title($post_ID);
		$tweet->url = $url;
		//$result = $tweet->updatestatus(); //real
		$result = 'http://localhost/'; //test
		$save = $result; //test
		if($result){
			//$data = new SimpleXMLElement($result);	
			//$save = $data->id;
			$save = 'http://twitter.com/'.$user.'/status/'.$save;
			update_post_meta($post_ID, 'tweet', $save);
		}
	}	
}
function fts_tweetit($post){
	$postid = $post->ID;
	$got_shorturl = get_post_meta($postid, 'shorturl', true);
	if ($got_shorturl){ $url = $got_shorturl; } else {$url = get_permalink($postid);}
	if ($_POST['post-tweet']){fts_tweet($postid, $url);}
}
add_action('publish_to_publish', 'fts_tweetit', 20);
?>